<?php
/**
 * Created by PhpStorm.
 * User: zlkmu
 * Date: 2017/10/6
 * Time: 11:50
 * 管理服务器房间的基类
 */
    require_once ('Room.php');
    class RoomManager{
        //保存当前麻将房间的列表,类型为room
        public $roomList = array();

        //创建房间
        public function createRoomID(){
            //创建唯一的房间ID号
            $roomID = $this->randRoomID();
            while(!$roomID){
                $roomID = $this->randRoomID();
            }
            return $roomID;
        }


        //辅助函数，生成房间ID号
        private function randRoomID(){
            $roomID = rand(100000, 999999);
            //检查是否重复
            foreach($this->roomList as $room){
                if($room->getRoomID() == $roomID){
                    return false;
                }
            }
            return $roomID;
        }

        //辅助函数，获取房间的数量
        public function getRoomCount(){
            return count($this->roomList);
        }

        //辅助函数，添加房间到管理列表
        public function  addRoomToList($roomId,$room){
            $this->roomList["$roomId"]=$room;
        }

        //获取到一个房间
        function getRoom($roomId){
            return $this->roomList["$roomId"];
        }

    }



?>